<template>
	<view class="pages">
		<uni-nav-bar left-icon="left"  backgroundColor="#F5F7F8" @clickLeft="back" right-icon="trash" @clickRight="showModel" title="关注技师" />
		<view class="box-content">
				<view class="technician-list">
					<view v-for="(item,index) in data" :key="index" style="margin-bottom: 34rpx;">
						<uni-swipe-action>
							<uni-swipe-action-item :right-options="options"  @click="cancelAttion(item)">
								<view class="every-technician-info" @click.stop="toPage(item)">
									<view class="left-show">
										<view class="technician-img">
											<image class="header-img" :src="item.work_clothes_image" mode="">
											</image>
											<image class="fangda-icon" src="../../static/jishi/big.png" mode="">
											</image>
										</view>
									</view>
									<view class="right-show">
										<view style="display: flex;align-items: center;">
											<view class="username">{{item.technician_nickname || item.real_name}}</view>
											<view class="fixed-loc">
												<image src="../../static/jishi/loc.png" mode=""></image>
												<view>{{(item.juli/1000).toFixed(2)}}km</view>
											</view>
											<view class="today-time">
												<view class="titles">最快上门</view>
												<view class="time">30分钟</view>
											</view>
										</view>
										<view class="tit">
											<view>{{item.age}}</view>
											<view>{{item.nation}}</view>
										</view>
										<view class="start-nums">
											<view class="start-show">
												<image v-for="(item,index) in item.gender" :key="index"
													src="../../static/jishi/start.png" mode=""></image>
												<image v-for="(item,index) in 5-item.gender" :key="index"
													src="../../static/jishi/no-start.png" mode=""></image>
											</view>
											<view class="pingjia-nums">
												<text>评论{{item.opinion}}</text>
												<text>好评{{((item.high_opinion/item.opinion || 0)*100).toFixed(0)}}%</text>
											</view>
										</view>

										<view class="brief-introduction">
											{{item.description?item.description:"暂无简介~"}}
										</view>
									</view>
								</view>
							</uni-swipe-action-item>
						</uni-swipe-action>
					</view>
				</view>
		</view>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="warn" cancelText="关闭" confirmText="同意" title="提示" content="是否全部取消关注？" @confirm="cancelAttionAll"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				options: [{
					text: '取消关注',
					style: {
						backgroundColor: '#EF5233'
					}
				}],
				// 滚动数据初始化
				visible_height: 60,
				solt_height: 0,
				page: 0,
				hasMore: true,
				data: [],
				data_number: 0,
			}

		},
		onPullDownRefresh(){
			this.loadData(1)
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onLoad() {
			this.loadData(0)
		},
		onReachBottom() {
			this.loadData(0)
		},
		methods: {
			toPage(item){
				uni.navigateTo({
					url:'/otherpages/technician/technician?id='+item.id
				})
			},
			back(){
				uni.navigateBack()
			},
			showModel(){
				this.$refs.alertDialog.open()
			},
			cancelAttionAll(){
				let that = this
				this.request.httpTokenRequest({
					url: "/service/closeCollect",
					method: "get"
				}, {
					type:1
				}).then(res => {
					if (res.code == 0) {
						this.loadData(1)
						this.$util.msg(res.msg)
					} else {
						this.$util.msg(res.msg)
						return
					}
				}, error => {})
			},
			cancelAttion(item){
				let that = this
				this.request.httpTokenRequest({
					url: "service/collect",
					method: "POST"
				}, {
					id:item.id,
					type: 1
				}).then(res => {
					if (res.code == 0) {
						this.loadData(1)
						this.$util.msg(res.msg)
					} else {
						this.$util.msg(res.msg)
						return
					}
				}, error => {})
				
			},
			loadData(type, callback) {
				uni.showLoading({
					title: "加载中"
				})
				let opts = {
					url: "user/collectService",
					method: 'get'
				};

				if (type == 1) {
					this.page = 0
					this.data = []
				}
			
				let param = {
					page: this.page,
					type: 1
				};

				this.request.httpTokenRequest(opts, param).then(res => {
					if (res.data.data.length < res.data.data.per_page) this.hasMore = false;
					// 把后端数据赋给页面	
					this.data = [...this.data, ...res.data.data];
					this.data_number = this.data.length
					this.page++
					
					// 隐藏加载条 重置下拉 上拉状态
					uni.hideLoading()
					if (type) callback(false)
				}, error => {

				})
			},

		}
	}
</script>

<style lang="scss">
	//
	.pages{
		padding-top: var(--status-bar-height);
	}
	.technician-list {
		margin-top: 30rpx;
	}
	.selectstyle {
		border: 2rpx solid #EF5233;
	}

	.every-technician-info {
		height: 261rpx;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 0 31rpx;
		position: relative;
		// margin-top: 30rpx;

		.left-show {
			position: absolute;
			left: 24rpx;
			top: 30rpx;

			.technician-img {
				width: 160rpx;
				height: 200rpx;
				position: relative;

				.header-img {
					width: 160rpx;
					height: 200rpx;
				}

				.fangda-icon {
					width: 30rpx;
					height: 30rpx;
					position: absolute;
					top: 10rpx;
					right: 10rpx;
				}

			}

			.choose-style {
				width: 118rpx;
				height: 30rpx;
				margin: 0 auto;
				margin-top: 30rpx;

				.no-choose {
					width: 115rpx;
					height: 30rpx;
					background: url('../../static/jishi/nochoose.png')no-repeat;
					background-size: 100% 100%;
					font-size: 20rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					padding-left: 17rpx;
					line-height: 30rpx;
				}

				.choose {
					width: 115rpx;
					height: 30rpx;
					background: url('../../static/jishi/choose.png')no-repeat;
					background-size: 100% 100%;
					font-size: 20rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					padding-left: 17rpx;
					line-height: 30rpx;
				}
			}
		}

		.right-show {
			position: absolute;
			left: 221rpx;
			top: 28rpx;
			right: 24rpx;

			.today-time {
				width: 186rpx;
				height: 32rpx;
				margin-left: 26rpx;
				background: url('https://qiniu-cdn.maeiyun.com/imgs/massage/bg.png')no-repeat;
				background-size: 100% 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 12rpx;

				.titles {
					font-size: 20rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
				}

				.time {
					font-size: 20rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #EF5233;
				}
			}

			.fixed-loc {
				margin-left: auto;
				display: flex;
				align-items: baseline;
				height: 30rpx;
				background: #F3F3F3;
				border-radius: 150rpx;
				padding: 0 14rpx;
				justify-content: center;
				align-items: center;
				line-height: 30rpx;

				view {
					font-size: 18rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #0F0807;
				}

				image {
					width: 14rpx;
					height: 18rpx;
					margin-right: 6rpx;
				}
			}

			.username {
				font-size: 28rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #0F0807;

				text {
					font-size: 20rpx;
				}
			}

			.tit {
				display: flex;
				align-items: center;
				margin-top: 15rpx;

				view {
					height: 30rpx;
					background: rgba(216, 216, 216, 0.46);
					border-radius: 8rpx;
					font-size: 20rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #0F0807;
					padding: 0 12rpx;
					margin-right: 10rpx;
					line-height: 30rpx;

				}
			}

			.start-nums {
				display: flex;
				align-items: center;
				margin-top: 15rpx;

				.start-show {
					margin-right: 42rpx;

					image {
						width: 19rpx;
						height: 18rpx;
					}
				}

				.pingjia-nums {
					display: flex;
					align-items: center;

					text {
						font-size: 20rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: #888889;
						margin-right: 10rpx;
					}
				}
			}

			.brief-introduction {
				font-size: 22rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #0F0807;
				margin-top: 14rpx;

			}
		}
	}

	//筛选弹窗
	.popup-content {
		width: 511rpx;

		.screening-condition {
			padding: 33rpx;
			border-bottom: 30rpx solid #D8D8D8;

			.screening-title {
				font-size: 28rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #000000;
				line-height: 40rpx;
			}

			.slider-content {
				margin-top: 55rpx;
				padding-bottom: 30rpx;
			}

			.sex-content {
				margin-top: 30rpx;

				.all-ok {
					width: 138rpx;
					height: 60rpx;
					border-radius: 30rpx;
					border: 1rpx solid #D7D7D7;
					font-size: 24rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #000000;
					text-align: center;
					line-height: 60rpx;
				}

				.all-ok-select {
					background: rgba(239, 82, 51, 0.1);
					border-radius: 30rpx;
					border: 1rpx solid #EF5233;
					color: #EF5233;
				}

				.else-sex {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 50rpx;

					.sex-box {
						width: 210rpx;
						height: 60rpx;
						border-radius: 30rpx;
						border: 1rpx solid #D7D7D7;
						display: flex;
						align-items: center;
						text-align: right;
						position: relative;

						view {
							width: 100%;
							font-size: 24rpx;
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							color: #000000;
							text-align: right;
							padding-right: 30rpx;
						}

						image {
							width: 89rpx;
							height: 89rpx;
							position: absolute;
							bottom: 0;
							left: 16rpx;
						}
					}

					.sex-box-select {
						background: rgba(239, 82, 51, 0.1);
						border-radius: 30rpx;
						border: 1rpx solid #EF5233;

						view {
							color: #EF5233;
						}
					}
				}
			}

			//
			.age-fillin {
				display: flex;
				align-items: center;
				margin-top: 30rpx;

				.lines {
					width: 18rpx;
					height: 1rpx;
					background-color: #979797;
					margin: 0 8rpx;
				}

				input {
					width: 210rpx;
					height: 60rpx;
					background: #F3F3F3;
					border-radius: 30rpx;
					font-size: 24rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #000000;
					text-align: center;
				}
			}

			.age-list {
				display: flex;
				align-items: center;
				justify-content: space-around;
				margin-top: 30rpx;

				view {
					width: 138rpx;
					height: 60rpx;
					border-radius: 30rpx;
					border: 1rpx solid #D7D7D7;
					font-size: 24rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #000000;
					line-height: 60rpx;
					text-align: center;
				}
			}

			.technician-name {
				width: 452rpx;
				height: 60rpx;
				background: #F3F3F3;
				border-radius: 30rpx;
				font-size: 24rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #000000;
				text-align: center;
				margin-top: 30rpx;
			}
		}
	}
</style>